home *** CD-ROM | disk | FTP | other *** search
- Path: seas.smu.edu!not-for-mail
- From: dbowman@post.smu.edu (Damon Bowman)
- Newsgroups: comp.lang.c++
- Subject: How to Get all Permutations
- Date: 16 Apr 1996 20:02:34 -0500
- Organization: Southern Methodist University - Bradfied Computer Center - Dallas
- Sender: usenet@seas.smu.edu
- Message-ID: <3174417f.15405235@sun.cis.smu.edu>
- NNTP-Posting-Host: sun.cis.smu.edu
- X-Nntp-Posting-Host: ax4-6.ppp.smu.edu
- X-Newsreader: Forte Agent .99d/32.182
-
- I'm writing a program in which I need to fill an array with all
- possible combinations of a group of numbers.
-
- For example, say you have the following table:
- Choices - A B C
- -------------------
- Person 1 - 1 2 3
- Person 2 - 2 3 1
- Person 3 - 3 1 2
-
- This is one possible combination out of 216 (#choices!)^#persons =
- 3!^3 = 216.
-
- In other words, each person must rank three choices in order of
- preference. I am trying to fill an array with every possible
- combination of all three persons' choices.
-
- The array would be structured: array[3][3][216], or:
- array[persons][choices][choices!^persons]
-
- I realize I am using math symbols, not C++ syntax, to explain my
- problem. I already have factorial and exponentiation functions to use.
-
- The rest of the program involves determining how many of the possible
- combinations result in a particular circular paradox whereby A is
- preferred to B, B is preferred to C, yet C is preferred to A. The
- paradox also occurs in reverse, whereby C is preferred to B, B is
- preferred to A, and A is preferred to C. The table above is an
- example of an occurence of this paradox.
-
- I have already figured out how to uncover all the cases containing the
- paradox, but can't quite get the array filled with all the possible
- combinations.
-
- I am also trying to write the program so that the number of choices
- and the number of persons is variable. In other words, I'm designing
- the program to work for tables of varying size, but for now I'm using
- integer data types. Still, it should work for 3, 4, 5, etc. persons,
- and I can upgrade the data types to a user defined type later that can
- hold larger numbers.
-
- Any help would be appreciated. By the way, this is not a school
- assignment, but rather a job for a professor teaching a class I'm not
- currently taking.
-